package com.linkwings.projectsimple.pojo;


import static javax.persistence.GenerationType.IDENTITY;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.linkwings.httpconverter.JacksonDateSerializer;
import com.linkwings.httpconverter.XStreamDateValueConverter;
import com.linkwings.projectsimple.bean.TestBean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamOmitField;


/**
 * @Transient //让hibernate 忽略该字段,放置于某个字段的get方法处
 *
 * SampleUser generated by hbm2java
 */
@XStreamAlias("user")// for xstream 根节点改名
@XmlRootElement(name = "user") //jaxb bean 根节点改名
//@JsonIgnoreProperties (value = { "id" ,  "password" })  //jackson 忽略多个属性
@Entity
@Table(name = "sample_user")
public class SampleUser implements java.io.Serializable {
	//, catalog = "project_sample"

	//@XStreamAsAttribute 将字段变成属性而不是节点 for xstream
	private Integer id;

	private String loginName;

	@XStreamOmitField //支持xstream 忽略该字段
	private String password;


	@XStreamConverter(XStreamDateValueConverter.class)// xstream 日期转换
	@XStreamAlias("birth-date") //xtream 字段改名
	private Date birthDatetime;

	private String nickName;

	private String email;

/*	private List<TestBean> testlist = new ArrayList<TestBean>();
	private Map<String,TestBean> testMap = new HashMap<String,TestBean>();
*/



	public SampleUser() {

	}

	public SampleUser(String loginName, String password, Date birthDatetime,
			String nickName, String email) {

		this.loginName = loginName;
		this.password = password;
		this.birthDatetime = birthDatetime;
		this.nickName = nickName;
		this.email = email;
	}


	//@JsonProperty(value="user_loging_id")//支持jackson 为节点改名
	@XmlElement(name = "userid") //支持jackson（需要改变默认的ObjectMapper） jaxb，为输出节点改名
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "login_name", length = 45)
	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	//@JsonIgnore //支持jackson 忽略该字段
	@XmlTransient //使用此jaxb 注解可以使得 jackson（需要改变默认的ObjectMapper） jaxb，忽略该字段
	@Column(name = "password", length = 45)
	public  String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@JsonSerialize (using = JacksonDateSerializer.class ) // jackson 日期转换 @see com.linkwings.httpconverter.JacksonDateSerializer
	//@XmlJavaTypeAdapter(SimpleDateJavaTypeAdapter.class) //使用此jaxb 注解可以使得 jackson（需要改变默认的ObjectMapper） jaxb，对日期字段进行format，SimpleDateJavaTypeAdapter需要自己实现
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "birth_datetime", length = 19)
	public Date getBirthDatetime() {
		return this.birthDatetime;
	}

	public void setBirthDatetime(Date birthDatetime) {
		this.birthDatetime = birthDatetime;
	}

	@Column(name = "nick_name", length = 45)
	public String getNickName() {
		return this.nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	@Column(name = "email", length = 45)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Override
	public String toString() {
		return "SampleUser [birthDatetime=" + birthDatetime + ", email="
				+ email + ", id=" + id + ", loginName=" + loginName
				+ ", nickName=" + nickName + ", password=" + password + "]";
	}



/*	@Transient //让hibernate 忽略该字段
	public List<TestBean> getTestlist() {
		return testlist;
	}

	public void setTestlist(List<TestBean> testlist) {
		this.testlist = testlist;
	}
	@Transient
	public Map<String, TestBean> getTestMap() {
		return testMap;
	}

	public void setTestMap(Map<String, TestBean> testMap) {
		this.testMap = testMap;
	}

*/

	/*
	 *
Hibernate Annotation使用笔记
   1. @Entity                         --声明为一个实体bean
   2. @Table(name="promotion_info")   --为实体bean映射指定表(表名="promotion_info)
   3. @Id                             --声明了该实体bean的标识属性
   4. @GeneratedValue                 --可以定义标识字段的生成策略.
   5. @Transient                      --将忽略这些字段和属性,不用持久化到数据库
   6. @Column(name="promotion_remark")--声明列(字段名="promotion_total") 属性还包括(length=200等)
   7. @Temporal(TemporalType.TIMESTAMP)--声明时间格式
   8. @Enumerated                     --声明枚举
   9. @Version                        --声明添加对乐观锁定的支持
  10. @OneToOne                       --可以建立实体bean之间的一对一的关联
  11. @OneToMany                      --可以建立实体bean之间的一对多的关联
  12. @ManyToOne                      --可以建立实体bean之间的多对一的关联
  13. @ManyToMany                     --可以建立实体bean之间的多对多的关联
  14. @Formula                        --一个SQL表达式，这种属性是只读的,不在数据库生成属性(可以使用sum、average、max等)
	 * */

}
